GraphQL Codegen
https://gyazo.com/422a6a667b49d620fb21aa0740f971b7
The Guild
website
github
#WIP
GraphQL Schemaを書いてserver/client向けに型を生成するやつ
基本的に型を生成するが、一部のpluginは実装を生成するものもある
例えば、react-queryで使いやすい形で生成してくれるなど
コマンド
https://the-guild.dev/graphql/codegen/docs/config-reference/codegen-config#cli-flags
$ bunx graphql-codegen --config codegen.ts
λ npx graphql-code-generator
codegenする
--watchするには@parcel/watcherが必要
@graphql-codegen/cli
Plugin
https://the-guild.dev/graphql/codegen/plugins
@graphql-codegen/typescript-operations
@graphql-codegen/typescript-resolvers
@graphql-codegen/typescript
GraphQLスキーマからTypeScriptの型を生成するプラグイン
エンティティやスカラー型をTypeScriptにマッピング
@graphql-codegen/schema-ast
GraphQL APIエンドポイントからスキーマファイルを生成するプラグイン
(既にスキーマファイルがある場合はオプション)
@0no-co/graphqlsp
GraphQL オートコンプリート用の TypeScript 言語サーバープラグイン (オプション)
@graphql-codegen/typescript-react-apollo
https://the-guild.dev/graphql/codegen/docs/guides/vanilla-typescript
Getting Started
Introduction
Installation
Development workflow
CIとかの話
開発中、@parcel/watcherで監視して自動生成できる
CodegenConfig
ESM TypeScript usage
Guides
Vanilla TypeScript
React Query
React / Vue
Apollo Server / GraphQL Yoga
Apollo Server / GraphQL Yoga with Server Preset
API Testing
GraphQL Modules
Further Reading
Config Reference
codegen.ts
schema field
documents field
plugin config
require field
Naming Convention
Lifecycle Hooks
Multi Project
Advanced Usage
Generated files colocation
Programmatic Usage
@graphql-codegen/core
CLIではなくプログラム内から生成指示したい時
How does it work?
Profiler
Document Transform
Integrations
VSCode Extension
Prettier & Linters
Apollo Federation
apollo-local-state
create-react-app
Gatsby
Writing Plugins
What are Plugins?
Plugin structure
Validate Configuration
Extend Schema
Using Visitor Pattern
Contributing
https://www.graphql-code-generator.com/docs/getting-started/installation
、GraphQLサーバーからスキーマを取得してTypeScriptの型定義が書かれたファイルを生成することができます。
graphql-codegenのツール群は、GraphQLを使って開発するなら絶対に知っておいたほうがいいと思うので、まだ知らない方は以下のドキュメントをサッと眺めてみることをおすすめします ref
https://techlife.cookpad.com/entry/2021/03/24/123214